﻿<%@ Page Title="Overview" ValidateRequest="false" EnableEventValidation="false" ViewStateEncryptionMode="Never" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Overview.aspx.cs" Inherits="LoadController._Overview" %>

<asp:Content runat="server" ID="FeaturedContent" ContentPlaceHolderID="FeaturedContent">

    <h1>Overview</h1>
    <h2>Active</h2>
    <asp:UpdatePanel ID="UpdatePanelActiveJob" runat="server" UpdateMode="Conditional">
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="TimerActiveJob" EventName="Tick" />
        </Triggers>
        <ContentTemplate>
            <asp:Timer ID="TimerActiveJob" runat="server" OnTick="ActiveJob_Tick" Interval="1000" Enabled="True" />
            <asp:Label ID="ActiveJobIsEmpty" runat="server" Visible="false">
                <span class="label info"><Label>No active job</Label></span>
            </asp:Label>

            <asp:Panel ID="Panel1" runat="server">
                <span class="label success">
                    <Label id="progressValue" runat="server"></Label></span>
                <div class="progress-bar">
                    <div class="bar bg-color-yellow" id="progressbarLeft" runat="server" style="width: 0%;"></div>
                    <div class="bar" id="progressbarRight" runat="server" style="width: 100%;"></div>
                </div>
            </asp:Panel>
        </ContentTemplate>
    </asp:UpdatePanel>

    <asp:UpdatePanel ID="UpdatePanelActiveJobGridView" runat="server" UpdateMode="Conditional">
        <ContentTemplate>
            <asp:GridView ID="GridViewActiveJob" Visible="false" runat="server" CssClass="hovered" AutoGenerateColumns="False" BorderWidth="0px" EnableViewState="false">
                <Columns>
                    <asp:BoundField DataField="RowKey" HeaderText="Name" />
                    <asp:BoundField DataField="ClassName" HeaderText="Service" />
                    <asp:BoundField DataField="MethodName" HeaderText="Method" />
                    <asp:BoundField DataField="InstanceCount" HeaderText="Instances" />
                    <asp:BoundField DataField="Duration" HeaderText="Duration" />
                    <asp:BoundField DataField="QueuedDateTime" HeaderText="Queued" />
                    <asp:TemplateField>
                        <ItemTemplate>
                            <a id="A1" href='Monitoring.aspx#<%# Eval("originalPK" )%>' title="Show job"><i class="icon-enter"></i></a>
                            <a id="A2" title="Abort active job" href="#" onclick="OpenAbortDialog();return false;"><i class="icon-stop"></i></a>
                        </ItemTemplate>
                    </asp:TemplateField>
                </Columns>
            </asp:GridView>
        </ContentTemplate>
    </asp:UpdatePanel>

    <asp:UpdatePanel ID="UpdatePanelQueue" runat="server" UpdateMode="Conditional">
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="TimerQueue" EventName="Tick" />
        </Triggers>
        <ContentTemplate>
            <asp:Timer ID="TimerQueue" runat="server" OnTick="Queue_Tick" Interval="5000" Enabled="true" />

            <div style="text-align: center; display: block;">
                <div style="display: table-cell; vertical-align: middle;">
                    <h2>Queue&nbsp;</h2>
                </div>
                <div style="display: table-cell; vertical-align: middle; width: 28px;">
                    <asp:UpdateProgress ID="UpdateProgressQueue" runat="server" AssociatedUpdatePanelID="UpdatePanelQueue">
                        <ProgressTemplate>
                            <img src="/Images/preloader-w8-cycle-black.gif" height="28" width="28" />
                        </ProgressTemplate>
                    </asp:UpdateProgress>
                </div>
            </div>

            <asp:Label ID="QueueIsEmpty" runat="server" Visible="false">
                <span class="label info"><Label>No jobs in queue</Label></span>
            </asp:Label>
            <asp:GridView ID="GridViewQueue" runat="server" CssClass="hovered" AutoGenerateColumns="False" BorderWidth="0px" AllowPaging="True" OnPageIndexChanging="GridViewQueue_PageIndexChanging">
                <Columns>
                    <asp:BoundField DataField="RowKey" HeaderText="Name" />
                    <asp:BoundField DataField="ClassName" HeaderText="Service" />
                    <asp:BoundField DataField="MethodName" HeaderText="Method" />
                    <asp:BoundField DataField="InstanceCount" HeaderText="Instances" />
                    <asp:BoundField DataField="Duration" HeaderText="Duration" />
                    <asp:BoundField DataField="QueuedDateTime" HeaderText="Queued" />
                    <asp:TemplateField>
                        <ItemTemplate>
                            <a id="A5" title="Delete job in queue" href="#" onclick='OpenDeleteQueueDialog("<%# Eval("PartitionKey" )%>", "<%# Eval("RowKey" )%>", "<%# Eval("QueuedDateTime" )%>");return false;'><i class="icon-cancel"></i></a>
                        </ItemTemplate>
                    </asp:TemplateField>
                </Columns>
            </asp:GridView>
        </ContentTemplate>
    </asp:UpdatePanel>

    <asp:UpdatePanel ID="UpdatePanelFinishedJobs" runat="server" UpdateMode="Conditional" >
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="TimerFinishedJobs" EventName="Tick" />
        </Triggers>
        <ContentTemplate>
            <asp:Timer ID="TimerFinishedJobs" runat="server" OnTick="FinishedJobs_Tick" Interval="5000" Enabled="true" />
            <div style="text-align: center; display: block;">
                <div style="display: table-cell; vertical-align: middle;">
                    <h2>Finished&nbsp;</h2>
                </div>
                <div style="display: table-cell; vertical-align: middle; width: 28px;">
                    <asp:UpdateProgress ID="UpdateProgressFinishedJobs" runat="server" AssociatedUpdatePanelID="UpdatePanelFinishedJobs">
                        <ProgressTemplate>
                            <asp:image ID="FinishedJobsLoading" runat="server" ImageUrl="~/Images/preloader-w8-cycle-black.gif" height="28" width="28" />
                        </ProgressTemplate>
                    </asp:UpdateProgress>
                </div>
            </div>
            <asp:Label ID="FinishedJobsIsEmpty" runat="server" Visible="false">
                <span class="label info"><Label>No jobs finished yet</Label></span>
            </asp:Label>
            <asp:GridView ID="GridViewFinishedJobs" runat="server" AllowPaging="True" OnRowCreated="GridViewFinishedJobs_RowCreated" AutoGenerateColumns="False" BorderWidth="0px" CssClass="hovered" OnPageIndexChanging="GridViewFinishedJobs_PageIndexChanging" PagerStyle-Wrap="False" PagerStyle-HorizontalAlign="Right">
                <Columns>
                    <asp:BoundField DataField="RowKey" HeaderText="Name" />
                    <asp:BoundField DataField="ClassName" HeaderText="Service" />
                    <asp:BoundField DataField="MethodName" HeaderText="Method" />
                    <asp:BoundField DataField="InstanceCount" HeaderText="Instances" />
                    <asp:BoundField DataField="Duration" HeaderText="Duration" />
                    <asp:BoundField DataField="QueuedDateTime" HeaderText="Queued" />
                    <asp:TemplateField>
                        <ItemTemplate>
                            <a id="A3" href='Monitoring.aspx#<%# Eval("PartitionKey" )%>' title="Show job"><i class="icon-enter"></i></a>
                            <a id="A4" title="Delete job" href="#" onclick='OpenDeleteDialog("<%# Eval("PartitionKey" )%>", "<%# Eval("RowKey" )%>", "<%# Eval("QueuedDateTime" )%>");return false;'><i class="icon-cancel"></i></a>
                        </ItemTemplate>
                    </asp:TemplateField>
                </Columns>
                <PagerStyle CssClass="pagination" BorderStyle="None" BorderWidth="0px" BorderColor="White" />
                    <PagerTemplate>
                        <div class="pagination">
                        <ul> 
                <li class="first"><asp:LinkButton runat="server" ID="Previous" CommandName="Page" CommandArgument="First"/></li>
                <li class="prev"><asp:LinkButton runat="server" ID="Button2" CommandName="Page" CommandArgument="Prev"/></li>
                <li class="spaces"><asp:LinkButton runat="server" ID="linkbutton6" Text="..." ></asp:LinkButton></li>
                <li><asp:LinkButton runat="server" ID="linkbutton1" CommandName="Page" ></asp:LinkButton></li>
                <li><asp:LinkButton runat="server" ID="linkbutton2" CommandName="Page" ></asp:LinkButton></li>
                <li><asp:LinkButton runat="server" ID="linkbutton3" CommandName="Page" ></asp:LinkButton></li>
                <li><asp:LinkButton runat="server" ID="linkbutton4" CommandName="Page" ></asp:LinkButton></li>
                <li class="spaces"><asp:LinkButton runat="server" ID="linkbutton5" Text="..." ></asp:LinkButton></li>
                <li class="next"><asp:LinkButton runat="server" ID="Button3" CommandName="Page" CommandArgument="Next" /></li>
                <li class="last"><asp:LinkButton runat="server" ID="Button4" CommandName="Page" CommandArgument="Last" /></li>
                    </ul>
                    </div>
                    </PagerTemplate>
                <%--<PagerTemplate>
                    <div class="pagination">
                        <ul>
                            <li class="first"><a></a></li>
                            <li class="prev"><a></a></li>
                            <li><a>1</a></li>

                            <li class="active"><a>1</a></li>
                            <li class="disabled"><a>1</a></li>
                            <li class="spaces"><a>...</a></li>

                            <li><a>N</a></li>
                            <li class="next"><a></a></li>
                            <li class="last"><a></a></li>
                        </ul>
                    </div>
                </PagerTemplate>--%>
            </asp:GridView>
        </ContentTemplate>
    </asp:UpdatePanel>

    <script type="text/javascript" src="/javascript/dialog.js"></script>
    <script type="text/javascript">
        function OpenAbortDialog() {
            $.Dialog({
                'title': 'Abort active job',
                'content': 'Are you sure you want to abort the active job?',
                'buttons': {
                    'Abort': {
                        'action': function () {
                            $.ajax({
                                type: "POST",
                                url: "Overview.aspx/AbortActiveJob",
                                data: "{}",
                                contentType: "application/json; charset=utf-8",
                                dataType: "json",
                                success: function (msg) {
                                    // Do something interesting here.
                                }
                            });
                        }
                    },
                    'Cancel': {
                        'action': function () { }
                    }
                }
            });
        };

        function OpenDeleteDialog(thejobid, name, queueddatetime) {
            $.Dialog({
                'title': 'Delete job',
                'content': 'Are you sure you want to delete the job <b>' + name + '</b>,</br>queued at ' + queueddatetime + '?',
                'buttons': {
                    'Delete': {
                        'action': function () {
                            $.ajax({
                                type: "POST",
                                url: "Overview.aspx/DeleteJob",
                                data: JSON.stringify({ jobid: thejobid }),
                                contentType: "application/json; charset=utf-8",
                                dataType: "json",
                                success: function () {
                                    window.location.reload();
                                }
                            });
                        }
                    },
                    'Cancel': {
                        'action': function () { }
                    }
                }
            });
        };

        function OpenDeleteQueueDialog(thejobid, name, queueddatetime) {
            $.Dialog({
                'title': 'Delete job in queue',
                'content': 'Are you sure you want to delete the job <b>' + name + '</b>,</br>queued at ' + queueddatetime + '?',
                'buttons': {
                    'Delete': {
                        'action': function () {
                            $.ajax({
                                type: "POST",
                                url: "Overview.aspx/DeleteJobInQueue",
                                data: JSON.stringify({ jobid: thejobid }),
                                contentType: "application/json; charset=utf-8",
                                dataType: "json",
                                success: function () {
                                    window.location.reload();
                                }
                            });
                        }
                    },
                    'Cancel': {
                        'action': function () { }
                    }
                }
            });
        };
    </script>
</asp:Content>

